Imports Microsoft.VisualBasic.FileIO

Public Class fManager

    Private iLastTabIndex As Integer = -1

    Private iSelectedAccountID As Integer

    Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged

        If iLastTabIndex > -1 Then
            SaveTabChanges(iLastTabIndex)
        End If

        iLastTabIndex = TabControl1.SelectedIndex

        Select Case TabControl1.SelectedIndex

            Case 0
                LoadServer1Tab()

            Case 1
                LoadAccountTab()

            Case 2
                LoadCharacterTab()

            Case 3
                LoadNewCharTab()

            Case 5
                LoadMapTab()

            Case 6
                LoadItemBaseTab()

        End Select

    End Sub

    Private Sub LoadServer1Tab()

        With Main.iniServer

            Me.txtLoginIP.Text = .GetString("LOGIN", "IP", "")
            Me.txtLoginPort.Text = .GetString("LOGIN", "PORT", 0)

            Me.txtServerName.Text = .GetString("SERVERINFO", "NAME", "")
            Me.txtClientVer.Text = EvoLib.Protocol.sClientVersion
            Me.txtTimeZone.Text = .GetString("SERVERINFO", "TIMEZONE", "")
            Me.numLoginAttempts.Value = CSng(.GetString("LOGIN", "MAXATTEMPTS", "3"))
            Me.numLockTime.Value = CSng(.GetString("LOGIN", "LOCKOUTTIME", "60"))

            Me.chkPKMode.Checked = .GetString("PKMODE", "ALLOWPK", False)
            Me.chkPKBagDrop.Checked = .GetString("PKMODE", "ENABLE_BAG_DROP", False)
            Me.chkPKBodyDrop.Checked = .GetString("PKMODE", "ENABLE_BODY_DROP", False)
            Me.numPKBagRate.Value = .GetString("PKMODE", "BAG_DROP_RATE", CStr(0.0))
            Me.numPKBodyRate.Value = .GetString("PKMODE", "BODY_DROP_RATE", CStr(0.0))

            Me.chkMobDrops.Checked = .GetString("MOBDROPS", "ALLOWDROPS", False)
            Me.chkMobBagDrop.Checked = .GetString("MOBDROPS", "ENABLE_BAG_DROP", False)
            Me.chkMobBodyDrop.Checked = .GetString("MOBDROPS", "ENABLE_BODY_DROP", False)
            Me.numMobBagRate.Value = .GetString("MOBDROPS", "BAG_DROP_RATE", CStr(0.0))
            Me.numMobBodyRate.Value = .GetString("MOBDROPS", "BODY_DROP_RATE", CStr(0.0))

            Me.numExpMulti.Value = .GetInteger("EXP", "RATE", 1)
            Me.numDrop.Value = .GetInteger("ITEMDROPS", "RATE", 1)

        End With

    End Sub

    Private Sub LoadAccountTab()

        Call btnAccountSearchGo_Click(Nothing, Nothing)

    End Sub

    Private Sub LoadCharacterTab()
        Call btnCharSearchGo_Click(Nothing, Nothing)
    End Sub

    Private Sub LoadNewCharTab()
        With Main.iniServer

            Me.txtStartMap.Text = .GetString("NEWCHAR", "MAP", "10")
            Me.numStartX.Value = .GetInteger("NEWCHAR", "X", 260)
            Me.numStartY.Value = .GetInteger("NEWCHAR", "Y", 206)

        End With

    End Sub

    Private Sub LoadMapTab()

        lstMaps.Items.Clear()


        If Microsoft.VisualBasic.FileIO.FileSystem.FileExists(Main.sServerPath & "\Map\map_info.txt") Then

            Dim stream As System.IO.StreamReader = FileIO.FileSystem.OpenTextFileReader(Main.sServerPath & "\Map\map_info.txt")
            Dim line As String

            Dim svr As String, file As String, mapname As String, Fmmap As Integer, strAttribs As String

            Do Until stream.EndOfStream

                Try

                    line = stream.ReadLine()
                    TrimLineTabs(line)

                    If Strings.Left(line, 1) <> ";" Then

                        svr = ReadNextValue(line)
                        file = ReadNextValue(line)
                        mapname = ReadNextValue(line)
                        Fmmap = CInt(ReadNextValue(line))
                        strAttribs = ReadNextValue(line)

                        Dim item As New ListViewItem
                        With item
                            item.Text = svr
                            item.SubItems.Add(file)
                            item.SubItems.Add(mapname)
                            item.SubItems.Add(Fmmap)
                            item.SubItems.Add(strAttribs)
                        End With

                        lstMaps.Items.Add(item)

                    End If

                Catch ex As Exception
                End Try

            Loop

        End If

    End Sub

    Private Sub AddMap()

        Dim server As String

        server = InputBox("Server name (without extension):", "Add Map")
        If server.Length = 0 Then Exit Sub

        Dim file As String

        file = InputBox("Map file name (without extension):", "Add Map")
        If file.Length = 0 Then Exit Sub

        Dim name As String

        name = InputBox("Map name:", "Add Map")
        If name.Length = 0 Then Exit Sub

        Dim strFmmap As String

        strFmmap = InputBox("Minimap Index (Fmmap):", "Add Map")
        If strFmmap.Length = 0 Then Exit Sub

        Dim strAttributes As String

        strAttributes = InputBox("Attributes:", "Add Map")
        If strAttributes.Length = 0 Then Exit Sub

        Dim W As System.IO.StreamWriter = FileSystem.OpenTextFileWriter(Main.sServerPath & "\Map\map_info.txt", True)
        W.WriteLine(server & " " & _
                    file & " " & _
                    Chr(34) & name & Chr(34) & " " & _
                    strFmmap & " " & _
                    Trim(strAttributes))
        W.Flush()
        W.Close()

        LoadMapTab()

    End Sub

    Public Sub LoadItemBaseTab(Optional selectedrow As Integer = 0)

        lstItemBase.Items.Clear()
        Dim itemtoselect As ListViewItem = Nothing

        With DatabaseManager.DB_Game

            Dim sSql As String = "SELECT * FROM TBL_ITEMBASE;"

            Dim rows As ArrayList = .ExecuteQuery(sSql)
            Dim item As ListViewItem

            If rows.Count > 0 Then
                For i As Integer = 0 To rows.Count - 1
                    item = New ListViewItem
                    item.Text = rows(i)("ID_ITEMBASE")
                    item.SubItems.Add(rows(i)("STR_NAME"))
                    item.SubItems.Add(System.Enum.GetName(GetType(Protocol.ItemType), rows(i)("BYTE_TYPE")))
                    item.SubItems.Add(rows(i)("INT_SHAPE"))
                    item.SubItems.Add(rows(i)("INT_LOOKS"))
                    lstItemBase.Items.Add(item)
                    If selectedrow > 0 And rows(i)("ID_ITEMBASE") = selectedrow Then itemtoselect = item
                Next
            End If

        End With

        If Not itemtoselect Is Nothing Then
            itemtoselect.EnsureVisible()
        End If

    End Sub

    Private Sub SaveTabChanges(ByVal tabindex As Integer)

        'MsgBox(tabindex)

        Select Case tabindex

            Case 0
                With Main.iniServer

                    .WriteString("LOGIN", "IP", Me.txtLoginIP.Text)
                    .WriteString("LOGIN", "PORT", Me.txtLoginPort.Text)

                    .WriteString("SERVERINFO", "NAME", Me.txtServerName.Text)
                    .WriteString("SERVERINFO", "CLIENTVERSION", Me.txtClientVer.Text)
                    .WriteString("SERVERINFO", "TIMEZONE", Me.txtTimeZone.Text)
                    .WriteString("LOGIN", "MAXATTEMPTS", Me.numLoginAttempts.Value)
                    .WriteString("LOGIN", "LOCKOUTTIME", Me.numLockTime.Value)

                    .WriteString("PKMODE", "ALLOWPK", Me.chkPKMode.Checked)
                    .WriteString("PKMODE", "ENABLE_BAG_DROP", Me.chkPKBagDrop.Checked)
                    .WriteString("PKMODE", "ENABLE_BODY_DROP", Me.chkPKBodyDrop.Checked)
                    .WriteString("PKMODE", "BAG_DROP_RATE", Me.numPKBagRate.Value)
                    .WriteString("PKMODE", "BODY_DROP_RATE", Me.numPKBodyRate.Value)

                    .WriteString("MOBDROPS", "ALLOWDROPS", Me.chkPKMode.Checked)
                    .WriteString("MOBDROPS", "ENABLE_BAG_DROP", Me.chkPKBagDrop.Checked)
                    .WriteString("MOBDROPS", "ENABLE_BODY_DROP", Me.chkPKBodyDrop.Checked)
                    .WriteString("MOBDROPS", "BAG_DROP_RATE", Me.numPKBagRate.Value)
                    .WriteString("MOBDROPS", "BODY_DROP_RATE", Me.numPKBodyRate.Value)

                    .WriteInteger("EXP", "RATE", Me.numExpMulti.Value)
                    .WriteInteger("ITEMDROPS", "RATE", Me.numDrop.Value)

                End With

            Case 3

                With Main.iniServer

                    .WriteString("NEWCHAR", "MAP", txtStartMap.Text)
                    .WriteInteger("NEWCHAR", "X", numStartX.Value)
                    .WriteInteger("NEWCHAR", "Y", numStartY.Value)

                End With

        End Select

    End Sub

    Private Sub fManager_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

        TabControl1_SelectedIndexChanged(Nothing, Nothing)

        e.Cancel = True
        Engine.bEnding = True

    End Sub

    Private Sub fManager_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Me.Show()
        Application.DoEvents()

        Call TabControl1_SelectedIndexChanged(Nothing, Nothing)

        With Main.iniServer

            If .GetString("NEWCHAR", "MAP", "") = "" Then

                .WriteString("NEWCHAR", "MAP", "10")
                .WriteInteger("NEWCHAR", "X", 260)
                .WriteInteger("NEWCHAR", "Y", 206)

            End If

        End With

    End Sub

    Private Sub btnAccountSearchGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAccountSearchGo.Click

        lstAccount.Items.Clear()

        With DatabaseManager.DB_Account

            Dim ssql As String

            If txtAccountSearch.Text.Length = 0 Then
                ssql = "SELECT * FROM TBL_LOGINS;"
            Else
                ssql = "SELECT * FROM TBL_LOGINS WHERE STR_USERNAME='" & txtAccountSearch.Text & "*';"
            End If

            Dim rows As ArrayList = .ExecuteQuery(ssql)
            Dim row As Collection
            Dim item As ListViewItem
            Dim id As Integer

            If rows.Count > 0 Then
                For i As Integer = 0 To rows.Count - 1

                    item = New ListViewItem

                    id = rows(i)("ID_LOGIN")
                    item.Text = id
                    item.SubItems.Add(rows(i)("STR_USERNAME"))
                    item.SubItems.Add(rows(i)("STR_EMAIL"))

                    row = .ExecuteQueryFirstRecord("SELECT * FROM TBL_GAMEMASTERLOGINS WHERE ID_LOGIN=" & id & " AND BOOL_DELETED='FALSE';")
                    If row.Count = 0 Then
                        item.SubItems.Add(" ")
                        item.SubItems.Add(" ")
                    Else
                        item.SubItems.Add("*")
                        If row("BOOL_IGNOREFILTER") Then
                            item.SubItems.Add("*")
                        Else
                            item.SubItems.Add(" ")
                        End If
                    End If

                    row = .ExecuteQueryFirstRecord("SELECT * FROM TBL_LOCK WHERE ID_LOGIN=" & id & " AND BOOL_DELETED='FALSE';")
                    If row.Count = 0 Then
                        item.SubItems.Add(" ")
                    Else
                        item.SubItems.Add("*")
                    End If

                    row = .ExecuteQueryFirstRecord("SELECT * FROM TBL_BAN WHERE ID_LOGIN=" & id & " AND BOOL_DELETED='FALSE';")
                    If row.Count = 0 Then
                        item.SubItems.Add(" ")
                    Else
                        item.SubItems.Add("*")
                    End If

                    row = .ExecuteQueryFirstRecord("SELECT BOOL_DELETED FROM TBL_LOGINS WHERE ID_LOGIN=" & id & ";")

                    If row("BOOL_DELETED") Then
                        item.SubItems.Add("*")
                    Else
                        item.SubItems.Add(" ")
                    End If

                    lstAccount.Items.Add(item)

                Next
            End If

        End With

        Call lstAccount_SelectedIndexChanged(Nothing, Nothing)

    End Sub

    Private Sub lstAccount_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstAccount.SelectedIndexChanged

        If lstAccount.SelectedItems.Count = 0 Then

            iSelectedAccountID = 0
            mnuResetPassword.Enabled = False
            mnuViewCharacters.Enabled = False

            mnuGMAccount.Enabled = False
            mnuIgnoreIPFilters.Enabled = False
            mnuLocked.Enabled = False
            mnuBanned.Enabled = False
            mnuDeleted.Enabled = False

            mnuGMAccount.Checked = False
            mnuIgnoreIPFilters.Checked = False
            mnuLocked.Checked = False
            mnuBanned.Checked = False
            mnuDeleted.Checked = False

        Else

            iSelectedAccountID = 0
            Dim id As Integer = lstAccount.SelectedItems(0).Text
            Dim row As Collection

            mnuResetPassword.Enabled = True
            mnuViewCharacters.Enabled = True
            mnuGMAccount.Enabled = True
            mnuBanned.Enabled = True
            mnuDeleted.Enabled = True

            With DatabaseManager.DB_Account

                row = .ExecuteQueryFirstRecord("SELECT BOOL_DELETED FROM TBL_LOGINS WHERE ID_LOGIN=" & id & ";")

                mnuDeleted.Checked = row("BOOL_DELETED")

                row = .ExecuteQueryFirstRecord("SELECT * FROM TBL_LOCK WHERE ID_LOGIN=" & id & " AND BOOL_DELETED='FALSE';")
                If row.Count = 0 Then
                    mnuLocked.Enabled = False
                    mnuLocked.Checked = False
                Else
                    mnuLocked.Enabled = True
                    mnuLocked.Checked = True
                End If

                row = .ExecuteQueryFirstRecord("SELECT * FROM TBL_BAN WHERE ID_LOGIN=" & id & " AND BOOL_DELETED='FALSE';")
                If row.Count = 0 Then
                    mnuBanned.Checked = False
                Else
                    mnuBanned.Checked = True
                End If

                row = .ExecuteQueryFirstRecord("SELECT * FROM TBL_GAMEMASTERLOGINS WHERE ID_LOGIN=" & id & " AND BOOL_DELETED='FALSE';")
                If row.Count = 0 Then
                    mnuGMAccount.Checked = False
                    mnuIgnoreIPFilters.Checked = False
                    mnuIgnoreIPFilters.Enabled = False
                Else
                    mnuIgnoreIPFilters.Enabled = True
                    mnuIgnoreIPFilters.Checked = row("BOOL_IGNOREFILTER")
                    mnuGMAccount.Checked = True
                End If

                If mnuDeleted.Checked Then

                    mnuLocked.Enabled = False
                    mnuBanned.Enabled = False
                    mnuGMAccount.Enabled = False
                    mnuIgnoreIPFilters.Enabled = False
                    mnuResetPassword.Enabled = False
                    mnuViewCharacters.Enabled = False

                End If

                iSelectedAccountID = id

            End With

        End If

    End Sub

    Private Sub mnuNewAccount_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuNewAccount.Click
        DatabaseManager.CreateAccount()
        LoadAccountTab()
    End Sub

    Private Sub mnuResetPassword_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuResetPassword.Click
        If iSelectedAccountID = 0 Then Exit Sub
        DatabaseManager.ResetPassword(iSelectedAccountID)
    End Sub

    Private Sub mnuSetupIPFilters_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSetupIPFilters.Click
        fGMFilter.Show()
    End Sub

    Private Sub mnuDeleted_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuDeleted.CheckedChanged
        If iSelectedAccountID = 0 Then Exit Sub
        DatabaseManager.SetDeleted(iSelectedAccountID, mnuDeleted.Checked)
        Call lstAccount_SelectedIndexChanged(Nothing, Nothing)
        LoadAccountTab()
    End Sub

    Private Sub mnuBanned_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuBanned.CheckedChanged
        If iSelectedAccountID = 0 Then Exit Sub
        DatabaseManager.SetBan(iSelectedAccountID, mnuBanned.Checked)
        LoadAccountTab()
    End Sub

    Private Sub mnuLocked_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuLocked.CheckedChanged
        If iSelectedAccountID = 0 Then Exit Sub
        If mnuLocked.Checked = False Then
            mnuLocked.Enabled = False
            DatabaseManager.RemoveLock(iSelectedAccountID)
        End If
        LoadAccountTab()
    End Sub

    Private Sub mnuIgnoreIPFilters_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuIgnoreIPFilters.CheckedChanged
        If iSelectedAccountID = 0 Then Exit Sub
        DatabaseManager.SetGMFilter(iSelectedAccountID, mnuIgnoreIPFilters.Checked)
        LoadAccountTab()
    End Sub

    Private Sub mnuGMAccount_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuGMAccount.CheckedChanged
        If iSelectedAccountID = 0 Then Exit Sub
        DatabaseManager.SetGM(iSelectedAccountID, mnuGMAccount.Checked)
        If mnuGMAccount.Checked Then
            mnuIgnoreIPFilters.Enabled = True
        Else
            mnuIgnoreIPFilters.Enabled = False
        End If
        LoadAccountTab()
    End Sub

    Private Sub tabCharacters_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tabCharacters.Click

    End Sub

    Private Sub cmbSearchType_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbCharSearchType.SelectedIndexChanged

        If cmbCharSearchType.SelectedIndex = 0 Then
            txtCharSearch.Enabled = False
        Else
            txtCharSearch.Enabled = True
        End If

    End Sub

    Private Sub btnCharSearchGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCharSearchGo.Click

        Dim ssql As String = "SELECT * FROM TBL_CHARACTER"

        Select Case cmbCharSearchType.SelectedIndex

            Case 0
                ssql &= ";"

            Case 1 'character name
                ssql &= " WHERE STR_NAME='" & txtCharSearch.Text & "';"

            Case 2 'username
                ssql &= " WHERE ID_LOGIN=" & DatabaseManager.GetIDLogin(txtCharSearch.Text) & ";"

        End Select

        Dim rows As ArrayList
        rows = DatabaseManager.DB_Game.ExecuteQuery(ssql)
        Dim item As ListViewItem

        lstCharacters.Items.Clear()

        If rows.Count > 0 Then
            For i As Integer = 0 To rows.Count - 1

                item = New ListViewItem
                item.Text = rows(i)("ID_CHARACTER")
                item.SubItems.Add(rows(i)("STR_NAME"))
                item.SubItems.Add(rows(i)("ID_LOGIN"))
                item.SubItems.Add(DatabaseManager.GetUsername(rows(i)("ID_LOGIN")))

                Select Case CType(rows(i)("BYTE_SEX"), Protocol.Gender)
                    Case Protocol.Gender.Male
                        item.SubItems.Add("M")
                    Case Protocol.Gender.Female
                        item.SubItems.Add("F")
                End Select

                Select Case CType(rows(i)("BYTE_JOB"), Protocol.CharacterJobs)
                    Case Protocol.CharacterJobs.Warrior
                        item.SubItems.Add("W")
                    Case Protocol.CharacterJobs.Taoist
                        item.SubItems.Add("T")
                    Case Protocol.CharacterJobs.Sorcerer
                        item.SubItems.Add("S")
                End Select

                If rows(i)("BOOL_DELETED") Then
                    item.SubItems.Add("*")
                Else
                    item.SubItems.Add(" ")
                End If

                lstCharacters.Items.Add(item)

            Next
        End If

    End Sub

    Private Sub tabServerInfo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tabServerInfo.Click

    End Sub

    Private Sub tabNewChar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tabNewChar.Click

    End Sub

    Private Sub btnCreateItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateItem.Click


        fCreateItem.Show()
    End Sub

    Private Sub btnAddMap_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddMap.Click
        AddMap()
        LoadMapTab()
    End Sub

    Private Sub btnEditMap_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEditMap.Click

        If lstMaps.SelectedItems.Count > 0 Then

            Editor.mCurrentMapFilename = lstMaps.SelectedItems(0).SubItems(1).Text
            Editor.mCurrentMap = New cMirMapFile(lstMaps.SelectedItems(0).SubItems(1).Text)
            Editor.mCurrentMapName = lstMaps.SelectedItems(0).SubItems(2).Text

            Editor.Show()

        End If

    End Sub

    Private MenuId As Integer
    Private mnuX As Integer, mnuY As Integer

    Private Sub lstItemBase_MouseDown(sender As Object, e As MouseEventArgs) Handles lstItemBase.MouseDown

        'check for a selection
        If lstItemBase.SelectedItems.Count > 0 And e.Button = MouseButtons.Right Then

            'store the ID_ITEMBASE
            MenuId = CInt(lstItemBase.SelectedItems.Item(0).Text)

            'show the context menu at the last known mouse coordinates
            mnuItemBase.Show(lstItemBase, mnuX, mnuY)

        End If

    End Sub

    Private Sub lstItemBase_MouseMove(sender As Object, e As MouseEventArgs) Handles lstItemBase.MouseMove

        'store the coordinates for opening the context menu
        mnuX = e.X
        mnuY = e.Y

    End Sub

    Private Sub mnuDelete_Click(sender As Object, e As EventArgs) Handles mnuDelete.Click

        If MenuId > 0 Then

            Dim sSql As String = "SELECT STR_NAME FROM TBL_ITEMBASE WHERE ID_ITEMBASE='" & MenuId & "';"
            Dim row As Collection = DatabaseManager.DB_Game.ExecuteQueryFirstRecord(sSql)

            If MsgBox("WARNING: Deleting items from the DB may cause serious errors! Are you sure you want to delete '" & row("STR_NAME") & "' from the database?", MsgBoxStyle.Exclamation Or MsgBoxStyle.YesNo, "Delete Item") = MsgBoxResult.Yes Then

                'set BOOL_DELETED to True for all existing items using this IDItemBase
                sSql = "UPDATE TBL_ITEMS SET BOOL_DELETED=" & True & " WHERE ID_ITEMBASE='" & MenuId & "';"
                DatabaseManager.DB_Game.ExecuteNonQuery(sSql)

                'actually delete the ItemBase line from TBL_ITEMBASE
                sSql = "DELETE FROM TBL_ITEMBASE WHERE ID_ITEMBASE='" & MenuId & "';"
                DatabaseManager.DB_Game.ExecuteNonQuery(sSql)

                'reset tmp ID_ITEMBASE variable
                MenuId = 0

            End If

        End If

    End Sub

    Private Sub mnuEdit_Click(sender As Object, e As EventArgs) Handles mnuEdit.Click

        If MenuId > 0 Then

            Dim Frm As fCreateItem = New fCreateItem

            Frm.Show()
            Application.DoEvents()

            Frm.LoadItem(MenuId)


        End If

    End Sub

    Private Sub mnuClone_Click(sender As Object, e As EventArgs) Handles mnuClone.Click

        If MenuId > 0 Then

            Dim Frm As fCreateItem = New fCreateItem

            Frm.Show()
            Application.DoEvents()

            Frm.LoadItem(MenuId, False)

        End If

    End Sub

    Private Sub btnCreateDefaultItems_Click(sender As Object, e As EventArgs) Handles btnCreateDefaultItems.Click

        If MsgBox("Are sure you want to create the default items?", MsgBoxStyle.Question Or MsgBoxStyle.YesNo, "ItemBase") = MsgBoxResult.Yes Then

            'call the create default items sub
            DatabaseManager.CreateDefaultItems()
            'refresh the item base view
            LoadItemBaseTab()

        End If

    End Sub


End Class